package com.etoak.controller;


import com.etoak.common.core.vo.PageVO;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.service.DishesService;
import com.etoak.vo.DishesVO;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author etoak
 * @since 2025-08-25
 */
@RestController
@RequestMapping("/dishes")
public class DishesController {
    @Autowired
    DishesService dishesService;
    //菜品添加
    @PostMapping
    public ResultVO<String> add(@Valid @RequestBody Dishes dishes){
        dishesService.add(dishes);
        return ResultVO.success();
    }
    //菜品查询
    @GetMapping("/list")
    public ResultVO<PageVO<DishesVO>> list(
            @RequestParam(required = false,defaultValue = "1")int pageNum,
            @RequestParam(required = false,defaultValue = "10")int pageSize,
            Dishes dishes
    ){
        PageVO<DishesVO> pageVO = dishesService.getList(pageNum, pageSize, dishes);
        return ResultVO.success(pageVO);
    }
    //菜品更新
    @PutMapping("/{id}")
    public ResultVO<Object> update(@PathVariable int id,@RequestBody Dishes dishes){
        dishesService.updateDishes(id,dishes);
        return ResultVO.success();
    }
    //删除菜品
    @DeleteMapping("/{id}")
    public ResultVO<Object> delete(@PathVariable int id){
        dishesService.deleteDishes(id);
        return ResultVO.success();
    }
}

